package com.exam.example.service.impl;

import org.hibernate.Session;
import org.hibernate.SessionFactory;
import org.hibernate.Transaction;

import com.exam.example.model.News;
import com.exam.example.model.Student;
import com.exam.example.service.StudentService;

public class StudentServiceImpl implements StudentService {

	
	SessionFactory sf = null;
	@Override
	public void addStudent(Student stu) {
		System.out.println("add Student");
		
		
		Session sess = this.sf.openSession();
		//开始事务
		Transaction tx = sess.beginTransaction();
		//创建消息实例
		News n = new News();
		//设置消息标题和消息内容
		n.setTitle("疯狂Java联盟成立了");
		n.setContent11("疯狂Java联盟成立了，"
			+ "网站地址http://www.crazyit.org");
		//保存消息
		sess.save(n);
		//提交事务
		tx.commit();
		//关闭Session
		sess.close();
	}
	@Override
	public void printSome(){
		System.out.println("add printSome");
	}
	
	
	public void setSf(SessionFactory sf) {
		this.sf = sf;
	}

}
